package com.junmeng.jdemo.recycler.chat.contextmenu;

import com.junmeng.jdemo.recycler.chat.contextmenu.base.IContextMenuManager;
import com.junmeng.jdemo.recycler.chat.contextmenu.base.IMenuViewManager;
import com.junmeng.jdemo.recycler.chat.contextmenu.base.ITypeContextMenu;
import com.junmeng.jdemo.recycler.chat.contextmenu.base.ITypeManager;
import com.junmeng.jdemo.recycler.chat.contextmenu.base.MenuListener;

import java.util.List;

public class ContextMenuManager implements IContextMenuManager<MenuInfo, String, Object> {

    private MenuListener<MenuInfo, Object> mClickListener;
    private IMenuViewManager<MenuInfo, Object> mMenuViewManager;
    private ITypeManager<String> mTypeManager;

    public ContextMenuManager() {
    }

    @Override
    public ContextMenuManager setMenuViewManager(IMenuViewManager menuViewManager) {
        mMenuViewManager = menuViewManager;
        return this;
    }

    @Override
    public ContextMenuManager setTypeManager(ITypeManager typeManager) {
        mTypeManager = typeManager;
        return this;
    }

    @Override
    public ContextMenuManager setMenuListener(MenuListener clickListener) {
        mClickListener = clickListener;
        return this;
    }

    @Override
    public void show(String type, Object userData) {
        ITypeContextMenu<MenuInfo> typeContextMenu = mTypeManager.getType(type);
        if (typeContextMenu == null) {
            return;
        }
        List<MenuInfo> menus = typeContextMenu.getMenuInfos();
        if (menus == null) {
            return;
        }
        mMenuViewManager.setMenuListener(mClickListener);
        mMenuViewManager.show(menus, userData);
    }

    @Override
    public void hide() {
        mMenuViewManager.hide();
    }
}
